<?php
  class SB_admin_m extends Model{
      function SB_admin_m(){
          parent::Model();
          $this->load->database();
      }
      
      function get_admin($per_page,$offset){
           $this->db->select();
           $this->db->from('admin');
           $this->db->limit($per_page,$offset);
           $this->db->order_by('id','DESC');
           $query=$this->db->get();
           return $query->result_array();
     }
     function add_admin($data){
         $query= $this->db->insert('admin',$data);
         return $query;
     }
     function login($data){
        $query=$this->db->get_where('admin',$data);
        return $query;
        }
     function change_pass($id,$new_pass){
        $this->db->where('id',$id);
        $this->db->update('admin',array('pass'=>$new_pass));
        }
     function is_password_match($id,$old_pass){
        $query= $this->db->get_where('admin',array('id'=>$id,'pass'=>$old_pass));
        if ($query->num_rows()>0){
            return TRUE;
        } return FALSE;
     }
     function delete_admin($id){
        return $this->db->delete('admin',array('id'=>$id));
     }
     function ident_exist($ident){
        $query=$this->db->get_where('admin',array('ident'=>$ident));
        if ($query->num_rows()==0) return false;
        else return true;
     }
//CONTENU    
     function get_contenu($page,$per_page,$offset){
        $this->db->select();
        $this->db->from('contenu');
        $this->db->where("page",$page);
        $this->db->limit($per_page,$offset);
        $this->db->order_by('id','DESC');
        $query=$this->db->get();
        return $query->result_array();
     }
     function add_contenu($data){
         $query= $this->db->insert('contenu',$data);
         return $query;
     }
     function get_detail_contenu($id){
        $query = $this->db->get_where('contenu', array('id'=>$id));  
        return $query;  
     }
     function modifier_contenu($data,$id){
        return $this->db->update('contenu',$data,array('id'=>$id));
     }     

//GESTION IMAGE
    function get_image($per_page,$offset){
        $this->db->select();
        $this->db->from('image');
        $this->db->limit($per_page,$offset);
        $this->db->order_by('page','DESC');
        $query=$this->db->get();
        return $query->result_array();
     }
     function update_image($id,$data){
         return $this->db->update('image',$data,array('id'=>$id));  
     }
     function add_image($data){
         $query= $this->db->insert('image',$data);
         return $query;
     }
     function get_image_by_ID($id){
        $query = $this->db->get_where('image', array('id'=>$id));  
        return $query;  
     }
     function delete_image($id){
        return $this->db->delete('image',array('id'=>$id));
     }

//BEGIN CONTACT     

         
  }
?>

